
<extend name="Application/Admin/View/layout.html" />
<block name="mid">
     <div id="page-wrapper">
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12">
                        <h1 class="page-head-line">商品添加</h1>
                        <h1 class="page-subhead-line">This is dummy text , you can replace it with your original text. </h1>

                    </div>
                </div>
                <!-- /. ROW  -->
                <div class="row">

<div class="col-md-6 col-sm-6 col-xs-12">
               <div class="panel panel-danger">
                        <div class="panel-heading">
                           SINGUP FORM
                        </div>
                        <div class="panel-body" >
                            <form role="form"  action="" method="post" enctype="multipart/form-data">

                                 <div class="form-group">
                                            <label>商品</label>
                                            <input type="text" class="form-control" name="goods_name">
                                     <p class="help-block">Help text here.</p>
                                        </div>
                                            <div class="form-group">
                                            <label>市场价格</label>
                                            <input type="text" class="form-control" name="marke_price" >
                                     <p class="help-block">Help text here.</p>
                                        </div>
                                        <div class="form-group">
                                            <label>本店价格</label>
                                            <input type="text" class="form-control" name="shop_price" >
                                     <p class="help-block">Help text here.</p>
                                        </div>
                                    <div class="form-group">
                                            <label>图片上传</label>
                                           <input type="file" multiple="" class="form-control" id="error" name="img" />
                                     <p class="help-block ">Help text here.</p>
                                        </div>

                                    <p class="help-block">Help text here.</p>



                                           <div class="form-group">
                                            <label>分类</label>
                                            <select class="form-control" name="cate_id">

                                               <foreach name="cate" item="v">

                                                <option value="{$v.id}">{$v.name}</option>
                                                </foreach>
                                            </select>
                                        </div>
                                          <div class="form-group">
                                            <label>品牌</label>
                                            <select class="form-control" name="brand_id">

                                               <foreach name="brand" item="v">

                                                <option value="{$v.id}">{$v.name}</option>
                                                </foreach>
                                            </select>
                                        </div>
                                           <div class="form-group">
                                            <label>商品类型</label>
                                            <select class="form-control" id="goods_type">

                                               <foreach name="cate" item="v">

                                                <option value="{$v.id}">{$v.name}</option>
                                                </foreach>
                                            </select>
                                        </div>



                                          <div class="form-group goods_spec" >
                                            <label >商品规格录入</label>

                                        </div>
<!--
                                           <div class="form-group">
                                        <label>颜色</label>
                                            <input name="pid" id="goods_type" width="750px" disabled value="黄色">
                                            <button class="btn btn-danger" type="button"> +</button>
                                              <input name="pid" id="goods_type" width="750px">


                                        </div>

                                        <div class="form-group">
                                            <label>颜色</label>
                                            <input name="pid" id="goods_type" width="750px" disabled value="黄色">
                                            <button class="btn btn-danger" type="button"> +</button>
                                              <input name="pid" id="goods_type" width="750px">


                                        </div> -->
                                               <div class="form-group">
                                            <label>上架</label>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_down" id="optionsRadios1" value="1" checked="">是
                                                </label>
                                            </div>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_down" id="optionsRadios2" value="2">否
                                                </label>
                                            </div>

                                        </div>
                                            <div class="form-group">
                                            <label>热销</label>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_hot" id="optionsRadios1" value="1" checked="">是
                                                </label>
                                            </div>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_hot" id="optionsRadios2" value="2">否
                                                </label>
                                            </div>

                                        </div>

    <div class="form-group">
                                            <label>新品</label>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_new" id="optionsRadios1" value="1" checked="">是
                                                </label>
                                            </div>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_new" id="optionsRadios2" value="2">否
                                                </label>
                                            </div>

                                        </div>


                                                   <div class="form-group">
                                        <label>编辑</label>
    <script id="editor"  name="desc" type="text/plain" style="width:700px;height:400px;"></script>


                                            </select>
                                        </div>
                                     <p class="help-block">Help text here.</p>
                                    <!--      <div class="form-group">
                                            <label>是否显示</label>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_show" id="optionsRadios1" value="option1" checked="">是
                                                </label>
                                            </div>
                                            <div class="radio">
                                                <label>
                                                    <input type="radio" name="is_show" id="optionsRadios2" value="option2">否
                                                </label>
                                            </div>

                                        </div> -->

                              <!--   <ul class="pagination">
                                  <li class="disabled"><a href="#">«</a></li>
                                  <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
                                  <li><a href="#">2</a></li>
                                  <li><a href="#">3</a></li>
                                  <li><a href="#">4</a></li>
                                  <li><a href="#">5</a></li>
                                  <li><a href="#">»</a></li>


                                </ul> -->
                           <ul  class="pagination">{$page}</ul>
                            </div>
                                    <p class="help-block">Help text here.</p>
                                        <button class="btn btn-danger" type="submit">提交 Now </button>
                                        <button class="btn btn-danger spec_add" type="button">规格录入 </button>


                                    </form>
                            </div>
                        </div>
                            </div>
        </div>
             <!--/.ROW-->


            </div>
            <!-- /. PAGE INNER  -->
        </div>

        </block>
         <block name="js">
<script type="text/javascript" charset="utf-8" src="__ROOT____Admin__ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__ROOT____Admin__ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="__ROOT____Admin__ueditor/lang/zh-cn/zh-cn.js"></script>
        <script type="text/javascript">
            $(function(){

                $('body').on('click','.spec_add',function(){
                       // alert(2);
                    var spec_price=0;
                    var spec_desc='';
                    var spec_id='';//规格规则
                    var price=$('.spec_item input[name="price"]');
                    var num=$(':text[name="spec_num"]').val();

                    // alert(num);
                    price.each(function(i,obj) {
                                //算总数
                        spec_price+=parseInt($(obj).val());
                         /* iterate through array or object */
                         // alert(total_price);
                        spec_desc+=$(obj).prev().attr('spec-desc')+";";
                        spec_id+='..'+$(obj).prev().attr('id');


                          // alert(spec_id);
                    });






                    $.ajax({
                        url: '{:U("admin/ajax/Appand_spec")}',
                        type:'POST',
                        dataType:'json',
                        data: {
                            'spec_rule':  spec_id,
                            'spec_price': spec_price,
                            'spec_desc': spec_desc,
                            'num': num,
                    },
                        success:function(e) {
                            // alert(1);

                    var html='';
                    html+=' <div class="table-responsive">';
                    html+='   <table class="table table-hover">';
                    html+='     <thead>';
                    html+='        <tr>';
                    html+='         <th>规格总价</th>';
                    html+='         <th>库存</th>';
                    html+='          <th>规格描述</th>';
                    html+='              <th>操作</th>';
                    html+='         </tr>';
                    html+='     </thead>';
                      for(i in e){
                    html+='    <tbody>';
                    html+='          <tr>';

                    html+='            <td>'+e[i].spec_price+'</td>';
                    html+='            <td>'+e[i].num+'</td>';
                               html+='            <td>'+e[i].spec_rule+'</td>';
                    html+='            <td>'+e[i].spec_desc+'</td>';
                    html+='            <td>00</td>';
                    html+='      </tr>';
                    html+='  </tbody>';
                    html+=' </table>';
                    html+=' </div>';
                    }
            $('.spec_price').after(html);

                        }
                    })


                })

 $('#goods_type').change(function(event) {
              var id=$(this).val();
         // alert(id);
              $.ajax({
                  url: '{:U("admin/ajax/GetSpec")}',
                  type: 'GET',

                  data: {
                     'id':id
                },
                DataType:'json',
                success:function(item){
                      // alert($('.goods_spec').attr('class'));

// alert(item);
                    var html='';
                for(i in item){

                        html+=' <div class="form-group spec_item">';
                        html+=' <label>'+item[i].spec_name+'</label>';
                        html+=' <div class="form-group" >';
                        html+='</div>';
                        for(j in item[i]['spec_item']){
                        html+=' <input name="pid" id="goods_type" width="750px" disabled value="'+item[i]['spec_item'][j]['name']+'">';
                        var desc=item[i].spec_name+':'+item[i]['spec_item'][j]['name'];

                        html+='<button class="btn btn-danger change-btn "   type="button" spec-desc="'+desc+'"    id="'+item[i]['spec_item'][j]['id']+'">+</button>';

                        // html+='<input name="pid" id="goods_type" width="750px" display="none">';
                                }

                        html+='</div>';
                        html+='<br/>';
                                }

                        html+=' <div class="form-group  spec_price">';
                        html+=' <label>商品规格库存</label>';
                        html+=' <div class="form-group" >';
                        html+='</div>';

                        html+=' <input name="spec_num" id="goods_type" width="750px"  value="">';



                        html+='</div>';
                        html+='<br/>';
                    $('.goods_spec').html(html)

            $('.change-btn').click(function(event) {

                      var icon=$(this).text();


                var th=$(this);
                if(icon=='+'){

                     $(this).parent().find(':text[name="price"]').remove();
                     $(this).parent().find('button').text('+');
                     // $(this).parent().siblings().find(':text[name="price"]').remove();


                     $(this).text('-');

                    var inp='<input id="goods_type" name="price" width="750px">';
                     $(this).after(inp);



                }else{

                    $(this).parent().find(':text[name="price"]').remove();

                    $(this).parent().find('button').text('+');
                    $(this).next().remove(':text[name="price"]');


                }

              })

                },




              })
              // .done(function() {
              //     console.log("success");
              // })
              // .fail(function() {
              //     console.log("error");
              // })
              // .always(function() {
              //     console.log("complete");
              // });
// //*/*/ alert(2);
// $('.goods_spec').on('click','.change-btn',function(){

//             // $('.change-btn').click(function(event) {
//                  // alert(1);
//                 // $(this).parent().find(':text[name="end"]').remove();
//                 // $(this).parent().find(':text[name="end"]').text('+');
//                 // alert(ss);
//                 var icon=$(this).text();
//                 var th=$(this);
//                 if(icon=='+'){
//                     alert(icon);
// alert(1);
//                      $(this).parent().find(':text[name="price"]').remove();
//                      $(this).parent().find('button').text('+');
//                      $(this).parent().siblings().find(':text[name="price"]').remove();


//                      $(this).text('-');

//                     var inp='<input id="goods_type" name="price" width="750px">';
//                      $(this).after(inp);



//                 }else{
// alert(icon);
// alert(2);
//                     $(this).parent().find(':text[name="price"]').remove();

//                     $(this).parent().find('button').text('+');
//                     $(this).next().remove(':text[name="price"]');


//                 }

//               })*/*/

            });









      // $('.fontawesome-icon-list a').click(function() {

      //    var icon=$(this).text();
      //    $('.icon').val(icon);

      // });




    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor('editor').focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor('editor').execCommand( "clearlocaldata" );
        alert("已清空草稿箱")
    }


    })

        </script>






        </block>